﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage.Streams;

namespace GYMm.Utils
{
    public class EmailUtils
    {
        public static async Task ShowComposeNewEmailAsync(IRandomAccessStream stream, String filename, String messageBody, String emailTo = null)
        {
            await ShowComposeNewEmailAsync(RandomAccessStreamReference.CreateFromStream(stream), filename, messageBody, emailTo);
        }
        public static async Task ShowComposeNewEmailAsync(RandomAccessStreamReference stream, String filename, String messageBody, String emailTo = null)
        {

            var emailMessage = new Windows.ApplicationModel.Email.EmailMessage();
            emailMessage.Body = messageBody;

            if (stream != null)
            {
                var attachment = new Windows.ApplicationModel.Email.EmailAttachment(filename, stream);
                emailMessage.Attachments.Add(attachment);
            }

            if (emailTo != null)
            {
                var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(emailTo);
                emailMessage.To.Add(emailRecipient);
            }

            await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage);
        }
    }
}
